﻿
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<div>
    <button id="get-one">Get One</button>
    <button id="get-all">Get All</button>
    <button id="post">Post</button>
    <button id="put">Put</button>
    <button id="delete">Delete</button>
</div>

@section scripts{
    <script>
        $(function () {
            $("#get-one").click(function () {
                $.ajax({
                    url: "/api/contactapi",
                    data: { Id: "teo@gmail.com" },
                    success: function (response) {
                        alert(response.Name);
                    },
                    type:"get"
                });
            });

            $("#get-all").click(function () {
                $.ajax({
                    url: "/api/contactapi",
                    data: { },
                    success: function (response) {
                        $(response).each(function (index, element) {
                            alert(element.Name);
                        });
                    },
                    type: "get"
                });
            });

            $("#post").click(function () {
                $.ajax({
                    url: "/api/contactapi",
                    data: {Email:"nghiemn@fpt.edu.vn", Name:"Nguyễn Nghiệm", Phone:"0913745789"},
                    success: function (response) {
                        $(response).each(function (index, element) {
                            alert(element.Name);
                        });
                    },
                    type: "POST"
                });
            });

            $("#put").click(function () {
                $.ajax({
                    url: "/api/contactapi/teo@gmail.com",
                    data: {Email: "nghiemn@fpt.edu.vn", Name: "Nguyễn Nghiệm", Phone: "0913745789" },
                    success: function (response) {
                        $(response).each(function (index, element) {
                            alert(element.Name);
                        });
                    },
                    type: "PUT"
                });
            });

            $("#delete").click(function () {
                $.ajax({
                    url: "/api/contactapi/teo@gmail.com",
                    data: { },
                    success: function (response) {
                        $(response).each(function (index, element) {
                            alert(element.Name);
                        });
                    },
                    type: "DELETE"
                });
            });
        });
    </script>
}